package Arrays;

//                              冒泡排序
import java.util.Arrays;

public class Test4 {
    //冒泡排序

    public static void bubbleSort(int[] arr){
        int i = 0;
        //冒的躺数
        for (i = 0; i < arr.length - 1; i++){
            //每一躺比较的次数
            int j = 0;
            for (j = 0; j < arr.length -1 - i; j++){
                if(arr[j] > arr[j + 1]){
                    int tmp = 0;
                    tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        int[] arr = new int[]{9, 5, 2, 7, 3, 6};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
